package com.my.xinyidaixi.Activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.my.xinyidaixi.DataBase.Bean.Dingdan;
import com.my.xinyidaixi.DataBase.Model.Over_UserModer;
import com.my.xinyidaixi.DataBase.Model.UserModel;
import com.my.xinyidaixi.R;

import org.apache.commons.lang3.StringUtils;

/**
 * Created by zw on 2017/8/8.
 */
public class queren_Order extends Activity {

    private ImageView order_fanhui;
    private TextView dingdanbianhao,xiadanshijian,name,tel,address,qujianshijian,yiwu,beizhu,price,youhuijuan,cost,sex,zhifuButton;
    private UserModel model=new Over_UserModer();
    private String UserPhone="",coupon_id="";
    private Dingdan dingdan;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.queren_order);
        initdata();
    }

    public void initdata()
    {
        order_fanhui = (ImageView) findViewById(R.id.queren_order_fanhui);
        order_fanhui.setOnClickListener(new Button());

        dingdanbianhao = (TextView) findViewById(R.id.queren_dingdanbianhao);
        xiadanshijian = (TextView) findViewById(R.id.queren_xiadanshijian);
        zhifuButton = (TextView) findViewById(R.id.queren_zhifu_button);
        zhifuButton.setOnClickListener(new Button());

        name = (TextView) findViewById(R.id.queren_name);
        sex = (TextView) findViewById(R.id.queren_sex);
        tel = (TextView) findViewById(R.id.queren_tel);
        address = (TextView) findViewById(R.id.queren_address);
        qujianshijian = (TextView) findViewById(R.id.queren_qujianshijian);
        yiwu = (TextView) findViewById(R.id.queren_yiwu);
        beizhu = (TextView) findViewById(R.id.queren_beizhu);
        price = (TextView) findViewById(R.id.queren_price);
        youhuijuan = (TextView) findViewById(R.id.queren_youhuijuan);
        cost = (TextView) findViewById(R.id.queren_cost);

        Intent intent=getIntent();


        dingdan = new Dingdan();

        UserPhone=model.getUser();
        dingdan.setUser_telphonenum(UserPhone);

        name.setText(intent.getStringExtra("name"));
        dingdan.setName(intent.getStringExtra("name"));

        sex.setText(intent.getStringExtra("sex"));
        dingdan.setSex(intent.getStringExtra("sex"));

        tel.setText(intent.getStringExtra("tel"));

        dingdan.setDizhi_telphonenum(tel.getText().toString());

        address.setText(intent.getStringExtra("address"));
        dingdan.setSchool(intent.getStringExtra("School"));
        dingdan.setAddress(intent.getStringExtra("address_info"));

        qujianshijian.setText(intent.getStringExtra("time"));
        dingdan.setQujiantime(intent.getStringExtra("time"));

        if(TextUtils.isEmpty(intent.getStringExtra("youhuijuan")))
        {
            youhuijuan.setText("未选择优惠卷");
            coupon_id="0"; //获取了优惠券的id
            dingdan.setYouhuijuan_id(coupon_id);
        }
        else
        {
            youhuijuan.setText(intent.getStringExtra("youhuijuan"));
            coupon_id=intent.getStringExtra("youhuijuan_id"); //获取了优惠券的id
            dingdan.setYouhuijuan_id(coupon_id);

        }

        price.setText(intent.getStringExtra("price")+"元");

        cost.setText(intent.getStringExtra("zongjia")+"元");
        dingdan.setPrice(intent.getStringExtra("zongjia"));

        beizhu.setText(intent.getStringExtra("beizhu"));
        dingdan.setBeizhu(intent.getStringExtra("beizhu"));

        yiwu.setText(intent.getStringExtra("yiwu"));
        dingdan.setYiwu(intent.getStringExtra("yiwu"));

        dingdan.setClean_type(intent.getStringExtra("clean_type"));

        String str= StringUtils.substringBefore(intent.getStringExtra("dingdanshijian"),".");
        xiadanshijian.setText(str);
        dingdan.setGettime(xiadanshijian.getText().toString());

        dingdanbianhao.setText(intent.getStringExtra("dingdanhao"));
        dingdan.setDingdanhao(dingdanbianhao.getText().toString());

    }


    public class  Button implements View.OnClickListener
    {
        @Override
        public void onClick(View v)
        {
            switch (v.getId())
            {
                case R.id.queren_order_fanhui:
                    queren_Order.this.finish();
                    overridePendingTransition(0,R.anim.ani_left_sign_out);//窗口向左滑出
                    break;
                case R.id.queren_zhifu_button:
                    Intent intent=new Intent();
                    Bundle bundle=new Bundle();
                    bundle.putSerializable("dingdan",dingdan);
                    intent.putExtras(bundle);
                    intent.setClass(queren_Order.this,zhifu_activity.class);
                    startActivityForResult(intent,3);
                    queren_Order.this.overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
                    break;
            }
        }
    }
    //按返回键 窗口向左滑出
    @Override
    protected void onPause()
    {
        super.onPause();
        queren_Order.this.overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(requestCode==resultCode)
        {
            queren_Order.this.setResult(3);
            queren_Order.this.finish();
            queren_Order.this.overridePendingTransition(R.anim.ani_right_get_into,R.anim.ani_left_sign_out);
        }
    }
}
